package com.zsc.common.web.util;

/**
 * CodeEnum.java是互动平台的客户端响应码枚举类。
 *
 * @author jason
 * @version 1.0 2017年3月16日
 */
public enum CodeEnum {

    /**
     * 服务端系统级固定响应码
     */
    code8200(200, 8200, "执行成功"),
    code8999(500, 8999, "服务器错误"),
    code990001(500, 990001, "不支持的mime请求类型"),
    code990002(500, 990002, "请求contentType 错误"),
    code990003(500, 990003, "请求文件大小超限"),
    code990004(500, 990004, "通讯协议参数 data / data_type 缺失"),
    code990005(500, 990005, "所指定的通讯协议版本无效"),
    code990006(500, 990006, "协议包解析错误"),
    code990007(500, 990007, "解析器无法定位模板视图"),
    code990008(500, 990008, "未知的请求 mime 类型"),

    /**
     * API接口级固定响应码
     */
    code990501(201, 990501, "请求参数无效(缺失，或为空，或不符合规则)"),
    code990502(201, 990502, "请求token无效"),
    code990503(201, 990503, "请求权限无效"),
    code990504(201, 990504, "验证码错误"),
    code990505(201, 990505, "请求业务执行失败"),
    code990506(201, 990506, "没有响应数据，即响应结果数据(result)不存在"),
    code990507(201, 990507, "请求已经过期"),
    code990508(201, 990508, "请求签名认证无效"),

    /**
     * 业务级响应码
     */
    // 直播服务系统(LVS)
    code9020101(201, 9020101, "当前用户不是主播"),
    code9020102(201, 9020102, "该主播没有开通直播房间"),
    code9020103(201, 9020103, "创建直播房间聊天室失败"),
    code9020104(201, 9020104, "该直播房间没有绑定主播助理"),
    code9020105(201, 9020105, "该直播房间绑定的主播助理用户信息不存在"),
    code9020106(201, 9020106, "该主播用户不存在"),
    code9020501(201, 9020501, "该直播房间不存在"),
    code9022101(201, 9022101, "用户财豆余额不足"),

    //用户认证系统（UDS/03）
    code9030101(503, 9030101, "数据库insert错误"),
    code9030102(201, 9030102, "该注册用户已经存在"),
    code9030201(503, 9030201, "验证码发送失败"),
    code9030401(403, 9030401, "用户名不存在"),
    code9030402(201, 9030402, "用户密码错误"),
    code9030403(201, 9030403, "数据库update错误"),
    code9030501(403, 9030501, "用户不存在"),
    code9030601(403, 9030601, "数据库查询为空"),
    code9030801(503, 9030801, "数据库update错误"),
    code9030802(403, 9030802, "该昵称已经被使用"),
    code9031301(503, 9031301, "数据库insert错误"),
    code9031401(403, 9031401, "用户名不存在"),
    code9031601(503, 9031601, "数据库update错误"),
    code9031602(201, 9031602, "用户密码错误"),

    // 用户充值服务(UCS/04) 充值响应码
    code9040101(201,9040101,"充值记录生成失败"),
    code9040201(201,9040201,"序列号对应的充值记录为空"),
    code9040202(201,9040202,"充值记录状态异常，即已支付或已取消"),
    code9040203(201,9040203,"充值记录所属用户与当前用户不一致"),
    code9040204(201,9040204,"支付宝WEB支付接口返回数据异常"),
    code9040205(201,9040205,"微信扫码支付接口返回数据异常"),
    code9040206(201,9040206,"找不到支付类型"),
	code9040501(201,9040501,"微信APP支付接口返回数据异常"),

	// 用户充值服务(UCS/04) 消费响应码
	code9040A01(201,9041001,"消费物品不存在"),
	code9040A02(201,9041002,"无法购买视频免费"),
	code9040A03(201,9041003,"已经购买此视频"),

    // 内容搜索服务(LVCS/08) 搜索响应码
    code9080100(201,9080100,"该讲师不存在"),
    code9080101(201,9080101,"该点播视频不存在"),
    code9080102(201,9080102,"该直播房间不存在");


    /**
     * 对应的httpcode，参照用
     */
    private int httpCode;

    /**
     * 业务code
     */
    private int code;

    /**
     * 描述信息
     */
    private String desc;

    CodeEnum(int httpCode, int code, String desc) {
        this.httpCode = httpCode;
        this.code = code;
        this.desc = desc;
    }

    public static boolean isSuccess(int code) {
        if (code == code8200.getCode()) {
            return true;
        }
        return false;
    }

    public int getHttpCode() {
        return httpCode;
    }

    public void setHttpCode(int httpCode) {
        this.httpCode = httpCode;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static int getHttpCodeByCode(int code) {
        CodeEnum[] codes = CodeEnum.values();
        for (CodeEnum c : codes) {
            if (c.getCode() == code) {
                return c.getHttpCode();
            }
        }
        return CodeEnum.code8999.httpCode;
    }
    }
